<template>
  <ve-line :data="chartData"></ve-line>
</template>

<script>
import VeLine from 'v-charts/lib/line.common';
import moment from 'moment';

export default {
  components: {
    VeLine
  },
  data() {
    return {
      chartData: {
        columns: ['日期', '微信小程序', '服务机构APP', '子女APP', '老人APP'],
        rows: []
      }
    };
  },
  async mounted() {
    let items = await this.$http.get(
      '/api/clientLog/adu',
      {params: {
        beginDate: moment().subtract(9, 'days').format('YYYY-MM-DD'),
        endDate: moment().format('YYYY-MM-DD')
        }
      });
    let daus = {};
    items.forEach(item => {
      const [ date, typeName, count ] = item;
      let dau = daus[date];
      if (!dau) {
        dau = daus[date] = {};
      }
      dau[typeName] = count;
    });

    let rows = [];
    for (let date in daus) {
      rows.push({'日期': date, ...daus[date]});
    }
    this.chartData.rows = rows;
    console.log(rows);
  }
}
</script>